#include <iostream>
#include <sys/wait.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
using namespace std;
pid_t pid;
void handle(int signo)
{
    //sleep(5);
    cout << "处理的信号是" << signo << endl;
    cout << "pid为" << getpid() << endl;
    while (true)
    {
        if(waitpid(-1, nullptr, WNOHANG)>0)
        {
            cout<<"等待子进程成功："<<pid<<endl;
        }
        else
        {
            break;
        }
    }
}
int main()
{
    cout << "当前进程的pid为" << getpid() << endl;
    //signal(SIGCHLD, handle);
    signal(SIGCHLD, SIG_IGN);
    for (int i = 0; i < 10; i++)
    {
        sleep(10);
        pid = fork();
        if (pid == 0)
        {
            int cnt = 5;
            while (cnt--)
            {
                sleep(1);
            }
            exit(0);
        }
    }
    while (true)
    {
    }

    return 0;
}